import os
import sys
import time

# 添加项目根目录到Python路径
ROOT_DIR = '/media/ross/8TB/project/lsh/deep_learning/DiffusionDet_mmdet/DiffusionDet'
sys.path.insert(0, ROOT_DIR)

from tools.mymodel_analysis_tools.HPO.train_hpo import HPOptimization


def main():
    # 配置基本参数 - 使用绝对路径
    base_config = os.path.join(ROOT_DIR,
                               "work_dirs/Hyperparametric_sensitivity/diffusiondet_r50_fpn_epoch_microalgeaOri20%_1lcm2_1adem2_1ddim4_1distill4.py")

    # 使用时间戳创建新的研究名称
    timestamp = int(time.time())
    study_name = f"diffusiondet_hpo_{timestamp}"
    storage = f"sqlite:///hpo_{timestamp}.db"

    work_dir = os.path.join(ROOT_DIR, "work_dirs/Hyperparametric_sensitivity/hpo_experiment")

    print(f"使用配置文件: {base_config}")
    print(f"工作目录: {work_dir}")
    print(f"研究名称: {study_name}")

    # 创建优化器
    optimizer = HPOptimization(
        base_config_path=base_config,
        work_dir=work_dir,
        n_trials=25,  # 根据您的显存调整为较小的值
        study_name=study_name,
        storage=storage
    )

    # 运行优化
    optimizer.run_optimization()


if __name__ == "__main__":
    main()
